package com.crm.service.impl.opportunityManager;

import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.dao.mapper.customerManager.DemandResearchMapper;
import com.crm.model.entity.customerManager.DemandResearch;
import com.crm.model.entity.customerManager.DemandResearchExample;
import com.crm.service.opportunityManager.DemandResearchDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 需求调研
 */
@Service
public class DemandResearchDbServiceImpl implements DemandResearchDbService {

    @Autowired
    private DemandResearchMapper demandResearchMapper;

    /**
     * 商机-商机详情-需求调研
     * @param opportunityId 商机id
     * @param order 分组数据
     * @return
     */
    @Override
    public List<DemandResearch> demandResearchList(String opportunityId, String order) {
        DemandResearchExample demandResearchExample = new DemandResearchExample();
        DemandResearchExample.Criteria criteria = demandResearchExample.createCriteria();
        demandResearchExample.setOrderByClause(order);
        criteria.andOpportunityIdEqualTo(opportunityId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<DemandResearch> list = demandResearchMapper.selectByExample(demandResearchExample);
        return list;
    }

    /**
     * 商机管理-商机详情-新增需求调研
     * @param demandResearch 需求调研实体
     * @return
     */
    @Override
    public Boolean addDemandResearch(DemandResearch demandResearch) {
        Boolean result = false;
        int num = demandResearchMapper.insertSelective(demandResearch);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 商机-商机详情-修改需求调研
     * @param demandResearchId 需求调研id
     * @return
     */
    @Override
    public DemandResearch getDemandResearchById(String demandResearchId) {
        return demandResearchMapper.selectByPrimaryKey(demandResearchId);
    }

    /**
     * 商机详情-修改需求调研
     * @param demandResearch 需求调研实体
     * @return
     */
    @Override
    public Boolean updateDemandResearch(DemandResearch demandResearch) {
        Boolean result = false;
        int num = demandResearchMapper.updateByPrimaryKeySelective(demandResearch);
        if(num>0){
            result = true;
        }
        return result;
    }
}
